package com.yauchu.kegra.graph.traversers;

import java.util.ArrayList;
import java.util.Iterator;

import org.jgrapht.DirectedGraph;

import com.yauchu.kegra.graph.GraphNode;
import com.yauchu.kegra.graph.NumberedEdge;

public class RefreshTraverser extends GraphNodeTraverser<Boolean>{
	
	
	public RefreshTraverser(DirectedGraph<GraphNode, NumberedEdge>graph)
	{
		super(graph);
	}
	
	public Boolean reduce(GraphNode current, ArrayList<Boolean> res)
	{
		
		Boolean result=current.getChanged();
		current.setChanged(false);
		
		Iterator<Boolean> boolIter= res.iterator();
		
		while(boolIter.hasNext())
		{
			result= boolIter.next()||result ;
		}
		
		if (result)
			{
			current.refreshCurrentRepresentation();
			}
		
				
		return result;
	}
	
	public void refreshOnDepth(GraphNode root, int depth)
	{
		
		reduceInOrderDownToDepth(root,depth);
		
	}

}
